<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <h2>{{ info }}</h2>
    <img src="../assets/images/snail.jpg" style="cursor: pointer" alt="" @click="imgClick">
    <div>
      {{$store.state.count}}
      <button @click="handleAddClick(10)">增加</button>
      <button @click="handleReduceClick(10)">减少</button>
      <button @click="handleActionsAdd(10)">异步增加</button>
      <button @click="handleActionsReduce(10)">异步减少</button>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'HelloWorld',
    data () {
      return {
        msg: 'Welcome to My Vue.js zsc',
        info: this.$store.state.name + this.$store.state.age,
        message:{
          name: 'zmm',
          age: '18岁'
        },
      }
    },
    created(){
      console.log('zmm',this)
      console.log('aaaaaaa')
      this.$store.commit('showPeople',this.message)
    },
    methods: {
      imgClick(){
        this.$router.push({
          path: '/'
        })
      },
      handleAddClick(n){
        this.$store.commit('mutationsAddCount',n)
      },
      handleReduceClick(n){
        this.$store.commit('mutationsReduceCount',n)
      },
      handleActionsAdd(n){
        this.$store.dispatch('actionAddAge',n);
      },
      handleActionsReduce(n){
        this.$store.dispatch('actionReduceAge',n);
      },
    },
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  h1, h2 {
    font-weight: normal;
  }
  ul {
    list-style-type: none;
    padding: 0;
  }
  li {
    display: inline-block;
    margin: 0 10px;
  }
  a {
    color: #42b983;
  }
</style>
